package com.gitee.zycra.future.job.common.param;

import com.gitee.zycra.future.job.common.model.JobUser;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.mindrot.jbcrypt.BCrypt;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class AddUserParam {

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String pwd;

    /**
     * 权限
     * @see com.gitee.zycra.future.job.common.enums.UserAuthEnum
     */
    private Integer auth;

    public static JobUser convertToJobUser(AddUserParam addUserParam) {
        if (addUserParam == null) {
            return null;
        }
        return new JobUser().setUsername(addUserParam.getUsername())
                .setPwd(BCrypt.hashpw(addUserParam.getPwd(), BCrypt.gensalt()))
                .setAuth(addUserParam.getAuth());
    }
}
